﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace XFPPT.NET.Models
{
    

    /// <summary>
    /// 响应对象，包含创建 PPT 请求的响应信息
    /// Response object containing information about the PPT creation request response
    /// </summary>
    public class PPTCreateResponse
    {
        /// <summary>
        /// 响应标识，指示响应的状态
        /// Response flag, indicating the status of the response
        /// </summary>
        public bool? flag { get; set; }

        /// <summary>
        /// 错误码，用于标识请求过程中可能出现的错误
        /// Error code, used to identify possible errors during the request
        /// </summary>
        public long? code { get; set; }

        /// <summary>
        /// 错误详情，提供关于错误的详细描述
        /// Error details, providing a detailed description of the error
        /// </summary>
        public string? desc { get; set; }

        /// <summary>
        /// 不用关注，预留字段
        /// Do not pay attention, reserved field
        /// </summary>
        public object? count { get; set; }

        /// <summary>
        /// 包含 PPT 创建相关详细数据的对象
        /// Object containing detailed data related to PPT creation
        /// </summary>
        public PPTCreateResponseData? data { get; set; }

        /// <summary>
        /// 请求唯一标识，当前为 null 可忽略
        /// Unique identifier for the request, currently null and can be ignored
        /// </summary>
        public object? sid { get; set; }

        [JsonIgnore]
        private string realJsonstring = string.Empty;

        /// <summary>
        /// Gets or sets the real JSON string representation of the response.
        /// 获取或设置响应的真实 JSON 字符串表示。
        /// </summary>
        [JsonIgnore]
        public string? RealJsonstring
        {
            get { return realJsonstring; }
            set
            {
                realJsonstring = value!;
                try
                {
                    DeserializePPTCreateResponse(value!);
                }
                catch (Exception)
                {
                    // 可添加日志记录等操作
                }
            }
        }

        /// <summary>
        /// 反序列化 PPT 创建响应的 JSON 字符串到当前对象。
        /// 此方法将传入的 JSON 字符串解析为对应的属性值，并赋值给当前对象的各个属性。
        /// </summary>
        /// <param name="json">待反序列化的 JSON 字符串。</param>
        public virtual void DeserializePPTCreateResponse(string json)
        {
            try
            {
                JsonNode? jsonNode = JsonNode.Parse(json);
                if (jsonNode != null)
                {
                    try
                    {
                        if (jsonNode["flag"] != null)
                        {
                            this.flag = Convert.ToBoolean(jsonNode["flag"]!.ToString());
                        }
                    }
                    catch { }
                    try
                    {
                        if (jsonNode["code"] != null)
                        {
                            this.code = Convert.ToInt64(jsonNode["code"]!.ToString());
                        }
                    }
                    catch { }
                    try
                    {
                        if (jsonNode["desc"] != null)
                        {
                            this.desc = jsonNode["desc"]!.ToString();
                        }
                    }
                    catch { }
                    try
                    {
                        if (jsonNode["count"] != null)
                        {
                            this.count = jsonNode["count"];
                        }
                    }
                    catch { }
                    if (jsonNode["data"] != null)
                    {
                        this.data = new PPTCreateResponseData();
                        var dataNode = jsonNode["data"]!;
                        try
                        {
                            if (dataNode["sid"] != null)
                            {
                                this.data.sid = dataNode["sid"]!.ToString();
                            }
                        }
                        catch { }
                        try
                        {
                            if (dataNode["coverImgSrc"] != null)
                            {
                                this.data.coverImgSrc = dataNode["coverImgSrc"]!.ToString();
                            }
                        }
                        catch { }
                        try
                        {
                            if (dataNode["title"] != null)
                            {
                                this.data.title = dataNode["title"]!.ToString();
                            }
                        }
                        catch { }
                        try
                        {
                            if (dataNode["subTitle"] != null)
                            {
                                this.data.subTitle = dataNode["subTitle"]!.ToString();
                            }
                        }
                        catch { }
                        try
                        {
                            if (dataNode["outline"] != null)
                            {
                                this.data.outline = dataNode["outline"]!.ToString();
                            }
                        }
                        catch { }
                    }
                    try
                    {
                        if (jsonNode["sid"] != null)
                        {
                            this.sid = jsonNode["sid"]!.ToString();
                        }
                    }
                    catch { }
                }
            }
            catch { }
        }
    }

    /// <summary>
    /// 包含 PPT 创建相关详细数据的类
    /// Class containing detailed data related to PPT creation
    /// </summary>
    public class PPTCreateResponseData
    {
        /// <summary>
        /// 请求唯一 id，用于标识本次 PPT 创建请求
        /// Unique request id, used to identify this PPT creation request
        /// </summary>
        public string? sid { get; set; }

        /// <summary>
        /// PPT 封面图链接，指向 PPT 封面图片的地址
        /// PPT cover image link, pointing to the address of the PPT cover image
        /// </summary>
        public string? coverImgSrc { get; set; }

        /// <summary>
        /// PPT 主标题，PPT 的主要标题信息
        /// PPT main title, the main title information of the PPT
        /// </summary>
        public string? title { get; set; }

        /// <summary>
        /// PPT 副标题，PPT 主标题下的次要标题信息
        /// PPT subtitle, the secondary title information under the PPT main title
        /// </summary>
        public string? subTitle { get; set; }

        /// <summary>
        /// PPT 大纲，展示 PPT 的主要结构和内容要点
        /// PPT outline, showing the main structure and key points of the PPT content
        /// </summary>
        public string? outline { get; set; }
    }
}
